package com.urea.web.controller.urea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.urea.common.annotation.Log;
import com.urea.common.core.controller.BaseController;
import com.urea.common.core.domain.AjaxResult;
import com.urea.common.enums.BusinessType;
import com.urea.system.domain.AgentTerminal;
import com.urea.system.service.IAgentTerminalService;
import com.urea.common.utils.poi.ExcelUtil;
import com.urea.common.core.page.TableDataInfo;

/**
 * 代理商终端绑定Controller
 * 
 * @author liuzd
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/agent/terminal")
public class AgentTerminalController extends BaseController
{
    @Autowired
    private IAgentTerminalService agentTerminalService;

    /**
     * 查询代理商终端绑定列表
     */
    @PreAuthorize("@ss.hasPermi('agent:terminal:list')")
    @GetMapping("/list")
    public TableDataInfo list(AgentTerminal agentTerminal)
    {
        startPage();
        List<AgentTerminal> list = agentTerminalService.selectAgentTerminalList(agentTerminal);
        return getDataTable(list);
    }

    /**
     * 导出代理商终端绑定列表
     */
    @PreAuthorize("@ss.hasPermi('agent:terminal:export')")
    @Log(title = "代理商终端绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AgentTerminal agentTerminal)
    {
        List<AgentTerminal> list = agentTerminalService.selectAgentTerminalList(agentTerminal);
        ExcelUtil<AgentTerminal> util = new ExcelUtil<AgentTerminal>(AgentTerminal.class);
        util.exportExcel(response, list, "代理商终端绑定数据");
    }

    /**
     * 获取代理商终端绑定详细信息
     */
    @PreAuthorize("@ss.hasPermi('agent:terminal:query')")
    @GetMapping(value = "/{untitled}")
    public AjaxResult getInfo(@PathVariable("untitled") Long untitled)
    {
        return success(agentTerminalService.selectAgentTerminalByUntitled(untitled));
    }

    /**
     * 新增代理商终端绑定
     */
    @PreAuthorize("@ss.hasPermi('agent:terminal:add')")
    @Log(title = "代理商终端绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgentTerminal agentTerminal)
    {
        return toAjax(agentTerminalService.insertAgentTerminal(agentTerminal));
    }

    /**
     * 修改代理商终端绑定
     */
    @PreAuthorize("@ss.hasPermi('agent:terminal:edit')")
    @Log(title = "代理商终端绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgentTerminal agentTerminal)
    {
        return toAjax(agentTerminalService.updateAgentTerminal(agentTerminal));
    }

    /**
     * 删除代理商终端绑定
     */
    @PreAuthorize("@ss.hasPermi('agent:terminal:remove')")
    @Log(title = "代理商终端绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{untitleds}")
    public AjaxResult remove(@PathVariable Long[] untitleds)
    {
        return toAjax(agentTerminalService.deleteAgentTerminalByUntitleds(untitleds));
    }
}
